﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace JSIF_WCFServer.UI
{
    /// <summary>
    /// GUI settings control for Bookshelf server
    /// </summary>
    public partial class SettingsControl : UserControl
    {
        /// <summary>
        /// Constructor
        /// </summary>
        public SettingsControl()
        {
            InitializeComponent();
        }

        private void checkBoxSharedRemoteAccess_CheckedChanged(object sender, EventArgs e)
        {
            bool allowRemote = checkBoxSharedRemoteAccess.Checked;
            checkBoxSharedLocalOnly.Enabled = allowRemote;
            checkBoxSharedReadOnly.Enabled = allowRemote;
            updateSharedAccessSummary();
        }

        private void checkBoxSharedReadOnly_CheckedChanged(object sender, EventArgs e)
        {
            updateSharedAccessSummary();
        }

        private void checkBoxSharedLocalOnly_CheckedChanged(object sender, EventArgs e)
        {
            updateSharedAccessSummary();
        }

        private void checkBoxSharedOtherPeople_CheckedChanged(object sender, EventArgs e)
        {
            updateSharedAccessSummary();
        }

        private void updateSharedAccessSummary()
        {
            StringBuilder sb = new StringBuilder();
            if (!checkBoxSharedOtherPeople.Checked)
            {
                sb.AppendLine("Only you will be able to use this bookshelf.");
            }
            else
            {
                if (!checkBoxSharedRemoteAccess.Checked)
                {
                    sb.AppendLine("Only users logged into this computer will be able to use this bookshelf.");
                }
                else
                {
                    if (checkBoxSharedLocalOnly.Checked)
                    {
                        sb.AppendLine("Only users on your home network or wifi will be able to use this bookshelf.  Make sure your firewall is configured to allow traffic on port " + 80 + ".");
                    }
                    else
                    {
                        sb.AppendLine("Anyone can use this bookshelf.  Make sure your firewall/router are configured to allow traffic on port " + 80 + ".");
                    }                    
                }
                if (checkBoxSharedReadOnly.Checked)
                {
                    sb.AppendLine("Only you will be able edit the stories on this bookshelf.");
                }
            }
            richTextBoxSharedAcessSummary.Text = sb.ToString();
        }
    }
}
